package com.woniu.outpatient.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.web.page.PageDomain;
import com.woniu.outpatient.domain.MoreRegistration;
import com.woniu.outpatient.service.UserDeptAndDoctorService;
import com.woniu.outpatient.service.IDoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniu.outpatient.domain.Registration;
import com.woniu.outpatient.service.IRegistrationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 挂号流水表Controller
 *
 * @author wolf-six
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/registration")
public class RegistrationController extends BaseController
{

    @Autowired
    private IDoctorService userDeptAndDoctorService;
    @Autowired
    private IRegistrationService registrationService;


    @GetMapping("/getEchartsList")
    public AjaxResult echarts()
    {
        List<BigDecimal> list = registrationService.getEchartsList();
        return success(list);
    }

    /**
     * 多表拼接查询挂号流水表列表
     */
    @RequiresPermissions("outpatient:registration:list")
    @GetMapping("/lists")
    public TableDataInfo lists(Registration registration)
    {
        startPage();
        List<MoreRegistration> list = registrationService.selectMoreRegistrationList(registration);
        return getDataTable(list);
    }

    @RequiresPermissions("outpatient:registration:list")
    @GetMapping("/okPayLists")
    public TableDataInfo okPayLists(Registration registration)
    {
        startPage();
        List<MoreRegistration> list = registrationService.selectOkPayMoreRegistrationList(registration);
        return getDataTable(list);
    }

    /**
     * 待诊队列 无未缴费的
     * @param registration
     * @return
     */
    @RequiresPermissions("outpatient:registration:list")
    @GetMapping("/PendingDiagnosis")
    public TableDataInfo PendingDiagnosis(Registration registration)
    {
        startPage();
        List<MoreRegistration> list = registrationService.selectPendingDiagnosisList(registration);
        return getDataTable(list);
    }

    /**
     * 修改挂号流水表状态
     */
    @RequiresPermissions("outpatient:registration:edit")
    @Log(title = "挂号流水表", businessType = BusinessType.UPDATE)
    @PostMapping("/changeListState")
    public AjaxResult changeListState(@RequestBody Registration registration)
    {
        return toAjax(registrationService.updateRegistrationStatus(registration));
    }


    /**
     * 查询挂号流水表列表
     */
    @RequiresPermissions("outpatient:registration:list")
    @GetMapping("/list")
    public TableDataInfo list(Registration registration)
    {
        startPage();
        List<Registration> list = registrationService.selectRegistrationList(registration);
        return getDataTable(list);
    }

    /**
     * 导出挂号流水表列表
     */
    @RequiresPermissions("outpatient:registration:export")
    @Log(title = "挂号流水表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Registration registration)
    {
        List<Registration> list = registrationService.selectRegistrationList(registration);
        ExcelUtil<Registration> util = new ExcelUtil<Registration>(Registration.class);
        util.exportExcel(response, list, "挂号流水表数据");
    }

    /**
     * 获取挂号流水表详细信息
     */
    @RequiresPermissions("outpatient:registration:query")
    @GetMapping(value = "/{registrationId}")
    public AjaxResult getInfo(@PathVariable("registrationId") Long registrationId)
    {
        return success(registrationService.selectRegistrationByRegistrationId(registrationId));
    }

    /**
     * 获取所有科室详细信息
     */
    @RequiresPermissions("outpatient:registration:query")
    @GetMapping("/getdeptList")
    public AjaxResult getdeptList()
    {
        return success(userDeptAndDoctorService.getdeptList());
    }

    /**
     * 获取所有医师详细信息
     */
    @RequiresPermissions("outpatient:registration:query")
    @GetMapping("/getDoctorList")
    public AjaxResult getDoctorList()
    {
        return success(userDeptAndDoctorService.getDoctorList());
    }

    /**
     * 新增挂号流水表
     */
    @RequiresPermissions("outpatient:registration:add")
    @Log(title = "挂号流水表", businessType = BusinessType.INSERT)
    @PostMapping("addRegistration")
    public AjaxResult add(@RequestBody Registration registration)
    {
        System.out.println("挂号成功");
        registration.setRegistrationMoney(new BigDecimal(10));
        registration.setState("已缴费");
        System.out.println(registration+"156354");
        return toAjax(registrationService.insertRegistration(registration));
    }

    /**
     * 修改挂号流水表
     */
    @RequiresPermissions("outpatient:registration:edit")
    @Log(title = "挂号流水表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Registration registration)
    {
        return toAjax(registrationService.updateRegistration(registration));
    }

    /**
     * 删除挂号流水表
     */
    @RequiresPermissions("outpatient:registration:remove")
    @Log(title = "挂号流水表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{registrationIds}")
    public AjaxResult remove(@PathVariable Long[] registrationIds)
    {
        return toAjax(registrationService.deleteRegistrationByRegistrationIds(registrationIds));
    }
}
